<?php
$menumark = 'commodity';

switch ($act) {
    case 'add':
//#####################@ 添加商品 @#####################//
        if($_p_pesubmit){
            if($_FILES['img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['img']);
                $_p_info['phone_img'] = $upload->filehost;
            }
            if($_FILES['img1']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['img1']);
                $_p_info['phone_img1'] = $upload->filehost;
            }
            if($_FILES['img2']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['img2']);
                $_p_info['phone_img2'] = $upload->filehost;
            }
            if($_FILES['img3']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['img3']);
                $_p_info['phone_img3'] = $upload->filehost;
            }
            
            if($res = $db->pe_insert('phone',$_p_info)){
                echo '<pre>';
            print_r($res);
            exit();
                pe_success('添加成功!');
            }else{
                echo '<pre>';
            print_r($res);
            exit();
                pe_error('添加失败!');
            }
        }
        $house_server = $db ->pe_selectall('category','','*');
        $brand_server = $db ->pe_selectall('brand','','*');
        $brand = json_encode($brand_server);
        $menutitle = '添加商品';
        include(pe_tpl('commodity_add.html'));
        break;

    case 'attr':
//#####################@ 商品属性 @#####################//
        $id = $_g_id;

        if($_p_pesubmit){

            if($_FILES['image1']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image1']);
                $_p_info['proattr_img1'] = $upload->filehost;


            }
            if($_FILES['image2']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image2']);
                $_p_info['proattr_img2'] = $upload->filehost;
            }
            if($_FILES['image3']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image3']);
                $_p_info['proattr_img3'] = $upload->filehost;
            }
            if($_FILES['image4']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image4']);
                $_p_info['proattr_img4'] = $upload->filehost;
            }
            if($_FILES['image5']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image5']);
                $_p_info['proattr_img5'] = $upload->filehost;
            }

            print_r($_p_info);


            if($db->pe_select("proattr",array('product_id'=>$id))){
                if($db->pe_update('proattr',array('product_id'=>$id),$_p_info)){
                    pe_success('操作成功!','admin.php?mod=product');
                }else{
                    pe_error('操作失败!');
                }
            }else{
                $_p_info['product_id'] = $id;
                if($db->pe_insert('proattr',$_p_info)){
                    pe_success('操作成功!','admin.php?mod=product');
                }else{
                    pe_error('操作失败!');
                }
            }





        }
        $menutitle = '商品属性';
        $info = $db->pe_select('proattr',array('product_id'=>$id));
        print_r($info);
        include(pe_tpl('product_attr.html'));
        break;

    case 'edit':
//#####################@ 修改商品 @#####################//
        $id = $_g_id;
        if($_p_pesubmit){

            if($_FILES['image']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['image']);
                $_p_info['product_img'] = $upload->filehost;
            }
            $_p_info['product_date'] = date('Y-m-d H:i:s');

            if($db->pe_update('product',array('product_id'=>$id),$_p_info)){
                pe_success('修改成功!','admin.php?mod=product&act=attr&id='.$id);
            }else{
                pe_error('修改失败!');
            }
        }
        $menutitle = '编辑商品';
        $info = $db->pe_select('product',array('product_id'=>$id));
        print_r($info);
        include(pe_tpl('product_add.html'));
        break;

    case 'state':
//#####################@ 修改商品首页显示 @#####################//
        $id = $_g_id;
        $state = $_g_state;
        if($info = $db->pe_update('product',array('product_id'=>$id),array('product_index'=>$state))){
            pe_success('修改成功!');
        }else{
            pe_error('修改失败!');
        }
        break;
    case 'del':
//#####################@ 修改商品首页显示 @#####################//
        if($db->pe_delete('product',array('product_id'=>is_array($_p_product_id)?$_p_product_id:$_g_id))){
            pe_success('删除成功!');
        }else{
            pe_error('删除失败!');
        }
        break;

    default:
//#####################@ 商品列表 @#####################//
        if($_g_name){
            $sql = " and product_name like '%$_g_name%' ";
        }
        $list = $db->pe_selectall('phone',$sql,'*', array(10, $_g_page));
        // print_r($list);

        include(pe_tpl('commodity_list.html'));
        break;
}





?>